/**
 * @Author yinyunqi
 * @date 2017年12月23日
 * @Content 
 */
package com.yongqi.pub;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class DateFormat {
    /**
     * 时间如2018-01-10 12:36:33
     * 此时时间
     * @return
     */
    public static String dateFormate() {
	Date date = new Date();
	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	String time = simpleDateFormat.format(date);
	return time;
    }
    /**
     * 时间如2018-01
     * 此时年月
     * @return
     */
    public static String dateFormate2(){
	Date date = new Date();
	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
	String time = simpleDateFormat.format(date);
	return time;
    }
    /**
     * 时间如2018-01之前一年的年月
     * @return
     */
    public static String dateFormate3(){
	Date date = new Date();
	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
	String time = simpleDateFormat.format(date);
	Integer year = Integer.valueOf(time.substring(0,4))-1;
	String month = time.substring(4,7);
	time = year+""+month;
	System.out.println(time);
	return time;
    }
    /**
     * 时间如2018-01,上个月
     * @return
     */
    public static String dateFormate4(){
	Date date = new Date();
	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(date);
	calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH)-1);
	date = calendar.getTime();
	String time = simpleDateFormat.format(date);
	return time;
    }
    /**
     * 时间如2018-01-01
     * 此时年月日
     * @return
     */
    public static String dateFormate5(){
	Date date = new Date();
	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
	String time = simpleDateFormat.format(date);
	return time;
    }
}

